﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Subcrible : System.Web.UI.Page
{
    bussiness bus;
     
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if(!IsPostBack)
        {
            if (Session["customer"] != null)
            {
                bus = new bussiness();
                Customer customer = (Customer)Session["customer"];
                txtCustomerId.Text = customer.CustomerId.ToString() ;
                txtName.Text = customer.Name;
                txtEmail.Text = customer.Email;
                txtStatus.Text = customer.Status;
                List<SubcribleType> lstSubcribleType = bus.getAllSubcribleType();
                Repeater1.DataSource = lstSubcribleType;
                Repeater1.DataBind();
            }
            else 
            {
               
                Response.Redirect("Login.aspx");
            }
        }

    }
    
    protected void Button2_Click(object sender, EventArgs e)
    {
        Customer customer = (Customer)Session["customer"];
        if (customer.Status == "subcrible")
        {
            lblError.Text = " you already registered !!!";
        }
        else
        {
            bus = new bussiness();
            //Get the reference of the clicked button.
            Button button = (sender as Button);

            //Get the command argument
            string commandArgument = button.CommandArgument;

            int subcribleTypeId = Convert.ToInt32(commandArgument);
            List<SubcribleType> lstSubcribleType = bus.getAllSubcribleType();
            foreach (SubcribleType sct in lstSubcribleType)
            {
                if (sct.SubcribleTypeId == subcribleTypeId)
                {
                    Session["SubcribleType"] = sct;
                    string redirectUrl = "";

                    //Mention URL to redirect content to paypal site
                    redirectUrl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" + ConfigurationManager.AppSettings["paypalemail"].ToString();

                    //First name I assign static based on login details assign this value
                    redirectUrl += "&first_name=nguoiban";

                    //Product Name
                    redirectUrl += "&item_name=" + sct.SubcribleName;

                    //Product Amount
                    redirectUrl += "&amount=" + sct.Price;

                    //Business contact paypal EmailID
                    redirectUrl += "&business=nguoiban12345@gmail.com";

                    //Shipping charges if any, or available or using shopping cart system
                    redirectUrl += "&shipping=1";

                    //Handling charges if any, or available or using shopping cart system
                    redirectUrl += "&handling=1";

                    //Tax charges if any, or available or using shopping cart system
                    redirectUrl += "&tax=1";

                    //Quantiy of product, Here statically added quantity 1
                    redirectUrl += "&quantity=1";

                    //If transactioin has been successfully performed, redirect SuccessURL page- this page will be designed by developer
                    redirectUrl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();

                    //If transactioin has been failed, redirect FailedURL page- this page will be designed by developer
                    redirectUrl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();

                    Response.Redirect(redirectUrl);
                }
            }
        }
    }
}